package com.lagou.edu.springbootrabbit.consumer;

import com.lagou.edu.springbootrabbit.dao.pojo.OrderPo;
import com.lagou.edu.springbootrabbit.dao.repository.OrderRepository;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderConsumer {
    @Autowired
    private OrderRepository orderRepository;

    //监听死信队列
    @RabbitListener(queues = "dlxqueue")
    public void service(String message) {
        System.out.println("消息队列推送来的消息：" + message);
        //查看订单，如果未支付，修改为取消；否则不用管
        OrderPo orderPo = orderRepository.findById(Integer.parseInt(message)).get();
        if(orderPo.getOrderStatus().equals("未支付")){
            orderPo.setOrderStatus("已取消");
            orderRepository.save(orderPo);
        }
    }
}